import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:liveplugin/live_push_view.dart';
import 'package:liveplugin/live_push_control.dart';
import 'package:liveplugin/type.dart';

/**
 *
 * @ProjectName:    live_plugin
 * @ClassName:      video_view_page
 * @Description:    dart类作用描述
 * @Author:         孙浩
 * @QQ:             243280864
 * @CreateDate:     2020/4/9 14:33
 */

class VideoViewPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _VideoViewPageState();
  }
}

class _VideoViewPageState extends State<VideoViewPage> {
  LivePushControl _control = LivePushControl();
  double strengthValue = 0;
  double beautyValue = 0.5;
  bool showWaterMarker = false;

  @override
  void initState() {
    super.initState();
    SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft]);

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
//      appBar: AppBar(),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
//          _control.setOnLiveListener((data){
//            print(data);
//          });
          _control.pushVideoStreaming(
              "rtmp://push.oshipe.com/live/fbdf37f3591c4ab2b4f9a485bf07d8f9?wsSecret=dadf6154129c62f85a25dc3f04226d01&wsTime=1590459606");

        },
        child: Icon(
          Icons.play_arrow,
          color: Colors.white,
        ),
      ),
      body: Stack(
        children: <Widget>[
          LivePushView(
            livePushControl: _control,
            vertical: false,
          ),
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            child: Container(
              height: double.infinity,
              width: double.infinity,
            ),
            onDoubleTap: () {
              _control.switchCamera();
            },
          ),
          Column(
            children: <Widget>[
              FlatButton(onPressed: (){
                _control.setBeauty(filterName: FilterData.HEIBAI2,filterValue: 1);
              }, child: Text("黑白")),
              FlatButton(onPressed: (){
                _control.setBeauty(filterName: FilterData.GEXING6,filterValue: 1);
              }, child: Text("个性")),
              FlatButton(onPressed: (){
                _control.changeOrigation();
              }, child: Text("切镜像"))
            ],
          ),
          Positioned(child: Slider(value: beautyValue, onChanged: (data){
            setState(() {
              beautyValue = data;
            });
            _control.setBeauty(whiteColor: data,redColor: data,blur: data);
          }),top:100 ,)
        ],
      ),
    );
  }

  @override
  void dispose() {
    _control.destroy();
    SystemChrome.setPreferredOrientations(
        [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]);
    super.dispose();
  }
}
